
var root = "webui4scope";

var protocol = "http://";
var host="10.0.0.146";
var port="8888";

var index_app = angular.module('index', ['ngRoute', 'ui.bootstrap', 'ngAnimate', 'ngSanitize']).config(
    ['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {

        $httpProvider.interceptors.push('httpInterceptor');

        $routeProvider
            .when('/',
                {
                    templateUrl : '/'+root+'/snack.html',
                    controller : SnackController
                })
            .when('/envs',
                {
                    templateUrl : '/'+root+'/views/env/env.html',
                    controller : EnvController
                })
            .when('/edit_env/:id',
                {
                    templateUrl : '/'+root+'/views/env/edit_env.html',
                    controller : EnvEditController
                })
            .when('/delete_env/:id',
                {
                    templateUrl : '/'+root+'/views/env/del_env.html',
                    controller : EnvDelController
                })
            .when('/create_env',
                {
                    templateUrl : '/'+root+'/views/env/create_env.html',
                    controller : EnvCreateController
                })
            .when('/scopeline_insts',
                {
                    templateUrl : '/'+root+'/views/scopebaseline/scopeline_inst.html',
                    controller : ShowScopeInstController
                })
            .when('/scopeline_inst_details/:scopeline_inst_id',
                {
                    templateUrl : '/' +root+ '/views/scopebaseline/scopeline_inst_detail.html',
                    controller:ScopelineInstDetailController
                })
            .when('/init_scopeline',
                {
                    templateUrl : '/'+root+'/views/scopebaseline/init_scopeline4env.html',
                    controller : ScopelineInitializeController
                })
            .when('/compare_scopeline',
                {
                    templateUrl : '/'+root+'/views/scopebaseline/scopebaseline_compare.html',
                    controller : CompareScopelineController
                })
//            .when('/edit_scopeline/:id', {templateUrl : '/'+root+'/views/scopebaseline/edit_scopebaseline.html', controller : EditScopeController})
//            .when('/scopeline_details', {templateUrl : '/'+root+'/views/scopebaseline/scopebaseline_details.html', controller : ScopeDetailController})
//            .when('/ops_records', { templateUrl : '/'+root+'/views/env/env.html', controller : OpsRecordController})
            .when('/charts',
                {
                    templateUrl : '/'+root+'/views/scopebaseline/chart.html',
                    controller : ChartController
                })
            .when('/about',
                {
                    templateUrl : '/'+root+'/about.html',
                    controller : AboutController
                })
            .when('/path',
                {
                    templateUrl : '/'+root+'/path.html',
                    controller : AboutController
                })
            .otherwise({redirectTo : '/'});
    }]
);

index_app.run(function($rootScope) {

    $rootScope.navbar_infos = {
        'g_components_pool_mgm' : '组件的二进制池的管理',
        'g_env_mgm' : '环境信息管理' ,
        'g_scope_inst' : 'scopebaseline 实例',
        'g_scope_spec' : 'scopebaseline 规格',
        'g_deploy_plan' : 'scopline实施计划',
        'g_charts_analysis' : '图表统计',
        'g_about' : '关于系统'
    }
    $rootScope.g_path = '123';

    // pagination vars
    $rootScope.start_point = 1;
    $rootScope.totalItems = 0;
    $rootScope.maxSize = 5;
    $rootScope.currentPage = 1;
    $rootScope.itemsPerPage = 5;

});


index_app.directive('content', function() {
    return {
            restrict:'EAC',
            transclude : true,
            template: function(){
                var _html = '';
                _html += '<div style="color: lightseagreen" ng-transclude></div>';
                return _html;
            }
    }
});

index_app.directive('routeLoadingIndicator', function($rootScope) {
    return {
        restrict: 'E',
        template: "<div ng-show='isRouteLoading' class='loading-indicator'>" +
            "<div class='loading-indicator-body'>" +
            "<h3 class='loading-title'></h3>" +
            "<div class='spinner'><rotating-plane-spinner><img src='/webui4scope/imgs/loading.gif' style='width: 40px; height: 40px'></rotating-plane-spinner></div>" +
            "</div>" +
            "</div>",
        replace: true,
        link: function(scope, elem, attrs) {
            scope.isRouteLoading = false;

            $rootScope.$on('$routeChangeStart', function() {
                scope.isRouteLoading = true;
            });
            $rootScope.$on('$routeChangeSuccess', function() {
                scope.isRouteLoading = false;
            });
        }
    };
});

index_app.directive('loader', ['$rootScope', function($rootScope) {

    return function ($rootScope, element, attrs) {
        $rootScope.$on("loader_show", function () {
            return element.show();
        });
        return $rootScope.$on("loader_hide", function () {
            return element.hide();
        });
    };
}]);


